﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using NetCore.Model
@using NetCore.BLL
@model List<PageEntity>
@inject IPageService pService
@{
    var lstItem = (List<PermissionEntity>)ViewData["ResourcePermission"];
    var PageAll = (List<PageEntity>)ViewData["PageAll"];
    bool selected = false;
}


@if (Model != null && Model.Count > 0)
{
    <ul>
        @foreach (var page in Model)
        {
            var lstChild = pService.GetChildTree(PageAll, page.PageId);
            selected = (lstItem != null && lstItem.Where(x => x.IsDisabled && x.ActionId == (page.PageId)).FirstOrDefault() != null);
            <li data-jstree='{"opened":true,"icon":"fa fa-sitemap","selected":@selected.ToString().ToLower(),"id":"@(page.PageId +"|"+page.RouteUrl)"}' id="@(page.PageId )">
                @(page.LocalName )
                @if (lstChild != null && lstChild.Count > 0)
                {
                    @await Html.PartialAsync("_unchildTree", lstChild)
                }
                @if (page.LstActions != null && page.LstActions.Count > 0)
                {
                <ul>
                    @foreach (var actions in page.LstActions)
                    {
                        selected = (lstItem != null && lstItem.Where(x => x.IsDisabled && x.ActionId == (actions.ActionCode)).FirstOrDefault() != null);
                        <li data-jstree='{"opened":true,"icon":"fa fa-leaf","selected":@selected.ToString().ToLower(),"id":"@((actions.ActionCode) +"|"+(page.RouteUrl+"/"+actions.ActionName))"}' id="@(page.PageId+"_"+ actions.ActionCode)">
                            @actions.Description
                        </li>
                    }
                </ul>
                }
            </li>
        }
    </ul>
}
